package MyQueue;

import java.util.List;

public class MyQueue {
    //为什么使用static而不是public
    static class ListNote {
        public int val;
        ListNote next;
        ListNote prev;

        public ListNote(int val) {
            this.val = val;
        }
    }

    public ListNote head;
    public ListNote last;
    public int useSize;

    public void push(int x) {
        ListNote date = new ListNote(x);
        if (head == null) {
            head = last = date;
        } else {
            date.prev = last;
            last.next = date;
            last = date;
        }
        useSize++;
    }

    public int pop() {
        int tmp = head.val;
        if (empty()) {
            return -1;
        } else {
            if (useSize == 1) {
                head = last = null;
            } else {
                head = head.next;
                head.prev = null;
            }
        }
        useSize--;
        return tmp;
    }

    public int peek() {
        if (head == null) {
            return -1;
        }
        return head.val;
    }

    public boolean empty() {
        return useSize == 0;
    }

    public void show() {
        if (head == null) {
            return;
        }
        ListNote cur = head;
        while (cur != null) {
            System.out.print(cur.val + " ");
            cur = cur.next;
        }
        System.out.println();
    }




}
